<div class="grid_container">
<script>
                                        $(document).ready(function() {
                                            $('#addSubalmacen').click(function(e) {
                                                $.ajax({
                                                    'url': url + '/warehouses/subwarehouses/',
                                                    'type': 'POST',
                                                    'data': {
                                                        'name': '',
                                                        'place': ''
                                                    },
                                                    'success': function(res) {
                                                        $('#add-product-model').html(res);
                                                    }
                                                });
                                                $('#add-product-model').modal();
                                                return false;
                                            });
                                             
                                        })
</script>
    <?php echo validation_errors('<strong>*','</strong><br/>'); ?>
    <?php
    $attributes = array(
        'id' => 'formAddGroups',
        'class' => 'form_container'
    );
    echo form_open_multipart('warehouses/submit', $attributes);?>
	<div class="grid_12">
		<div class="widget_wrap">
			<div class="widget_top">
				<span class="h_icon money"></span>
				<h6><?= isset( $warehouse->id)? 'Editar':'Agregar'  ?>  Almacén</h6>
			</div>
			<div class="widget_content">
				<ul>
					<li>
						<div class="form_grid_12">
							<div class="form_input">
								<div class="form_grid_12 alpha">
									<label class="field_title"> Nombre <span class="req">*</span></label>
									<?php
                                    $data = array(
                                        'name'        => 'name',
                                        'id'          => 'name',
                                        'class'       => 'noEmpty',
                                        'value'       => @field(set_value('name'), $warehouse->name),
                                        'tabindex'    => '1',
                                        'required'    => 'required'
                                    );
                                    echo form_input($data);
                                    ?>
								</div>
								<span class="clear"></span>
							</div>
						</div>
					</li>
					<li>
						<div class="form_grid_12">
							<div class="form_input">
								<div class="form_grid_12 alpha">
									<span class="field_title">Dirección <span class="req">*</span></span>
									<?php
                                    $data = array(
                                        'name'        => 'text',
                                        'id'          => 'text',
                                        'class'       => 'noEmpty',
                                        'value'       => @field(set_value('text'), $warehouse->text),
                                        'tabindex'    => '1',
                                        'required'    => 'required'
                                    );
                                    echo form_input($data);
                                    ?>
								</div>
								<span class="clear"></span>
							</div>
						</div>
					</li>
				</ul>
			</div>
                    <div class="form_grid_2 " style="margin-bottom: 10px; float: right">
                        <button id="addSubalmacen" type="button" class="btn_small btn_blue"><span>Agregar Sub-Almacen</span></button>
                                    </div>
                    <table class="wtbl_list">
                        <thead>
                            <tr class="tr_1">
                                
                                <th width="30%">Descripción</th>
                                <th width="30%">Ubicación</th> 
                                <th width="10%"></th>
                            </tr>

                        </thead>

                        <tbody id="contentProductList" class="contentProductList">
<?php
if (isset($datesale)) {
    $contandoitem = 0;
   
    foreach ($subwarehouses as $sa) {                            
        $contandoitem++;       
        ?>
                                <script>
                                    
                                    $(document).ready(function() {
                                                                               
                                        
                                        $('#contenaumentador').val(<?php echo $contandoitem; ?>);
                                        

                                        $('.eliminar_<?php echo $contandoitem; ?>').click(function() {

                                            if (confirm('¿Desea eliminar este Sub-almacén?')) {

                                                 var contandoitem = $('input[name=contandoitem]').val();



                                                $('input[name=contandoitem]').val(contandoitem - 1);

                                                $.ajax({
                                                    'url': url + '/warehouses/delete_subalmacen',
                                                    'type': 'POST',
                                                    'data': {
                                                        'code': $('input[name=code_product_a<?php echo $contandoitem; ?>]').val()
                                                    },
                                                    'success': function(res) {
                                                        if (res != 1) {
                                                            alert('Elminado con exito');                                                             
                                                        } else {
                                                            alert('No se pudo eliminar el producto.');
                                                        }
                                                    }
                                                });

                                                $('tr.fila_<?php echo $contandoitem; ?>').remove();

                                            } else {

                                            }
                                        })


                                    })
                                </script>  
                                 
                                <tr class="fila_<?php echo $contandoitem; ?>">
                                    
                                        <input type="hidden" name="code_product_a<?php echo $contandoitem; ?>" value="<?php echo $sa->id_subwarehouse; ?>">
                                        
                                    <td align="center">
                                        <input type="hidden" name="description_a<?php echo $contandoitem; ?>" value="<?php echo $sa->name; ?>">
                                <?php echo $sa->name; ?>
                                    </td>
                                    <td align="center">
                                        <input type="hidden" name="description_a<?php echo $contandoitem; ?>" value="<?php echo $sa->place; ?>">
                                <?php echo $sa->place; ?>
                                    </td> 
                                    <td align="center"><a href="#"  class="action-icons c-Delete eliminar_<?php echo $contandoitem; ?>">Delete</a></td>
                                </tr>
                        <?php
                        }
                    } else {
                        
                    }
                    ?>                            


                    <input type="hidden" name="contador_detalles" id="contador_detalles" value="0" >
                        </tbody>



                    </table>
                    
                    <script type="text/javascript" >
                    var contando = 0;
                                            function contandoitem(dato) {
                                                contando = dato;
                                                $('#contenaumentador').val(contando);
                                            }    
                    </script>
                    <input type="hidden" name="contandoitem" value="<?php
                           if (isset($contandoitem)) {
                               echo $contandoitem;
                           }
                    ?>">

                    
                    <input type="hidden" name="contenaumentador" id="contenaumentador" value="0">
                  <br />
                   <br />
                    
	    </div>
		<br />
		<?php echo form_hidden("warehouse_id", @field($warehouse->id, "")); ?>
		<button type="submit" class="btn_small btn_orange"><span>Guardar</span></button>
                <?php  if(isset($warehouse->id)){?>
                <button type="button" class="btn_small btn_orange"><span><a id="buscar_guia" href="<?php echo base_url(); ?>index.php/warehouses_list_index/">Cancelar</a></span></button>
                <?php } else{?>
 <button type="button" class="btn_small btn_orange"><span><a id="buscar_guia" href="<?php echo base_url(); ?>index.php/warehouses/add">Cancelar</a></span></button>

                <?php }?>
	</div>
    <?php echo form_close(); ?>
	<span class="clear"></span>
</div>
<div id="add-product-model">
</div>